package com.lidy.tankbattle.tankgame1;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Random;

/**
 * @author lidy
 * @version V1.0
 * @classname EnemyTank
 * @description 敌方坦克
 * @date 2022/5/29 10:36
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class EnemyTank extends Tank implements Runnable {

    /**
     * 发射子弹间隔时间
    **/
    private int randomSeed;

    public EnemyTank(int x, int y, int direction, int number, int bloodVolume, int randomSeed) {
        super(x, y, 1, direction, number, bloodVolume);
        this.randomSeed = randomSeed;
    }

    /**
     * 每隔一秒发射一颗子弹
    **/
    @Override
    public void run() {
        while (getLive()) {
            try {
                Random random = new Random(randomSeed);
                Thread.sleep(random.nextInt(400) + 600);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //
            shot();
        }
    }

}
